package cn.gov.pbc.dream.pojo.bo;

import cn.gov.pbc.dream.common.BankFinancingProductRaiseInfoConst.CustomerType;

import cn.gov.pbc.dream.common.BankFinancingProductRaiseInfoConst;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@ToString
public class PIB2Bo {
    private List<BufferedReader> bufferedReaderList = new ArrayList<>();

    private List<ProductRaiseInfo> productRaiseInfoList = new ArrayList<>();

    public void assembleProductRaiseInfoList(String data) {
        String[] values = data.split("\\|", 7);
        ProductRaiseInfo productRaiseInfo = new ProductRaiseInfo();
        productRaiseInfo.setBankFinancingProductCode(values[0]);
        productRaiseInfo.setAreaCode(values[1]);
        productRaiseInfo.setCustomerType(BankFinancingProductRaiseInfoConst.CustomerType.codeOf(Integer.parseInt(values[2])));
        productRaiseInfo.setCurrencyCode(values[3]);
        if (StringUtils.isNotBlank(values[4])) {
            productRaiseInfo.setRaiseAmount(new BigDecimal(values[4]));
        }
        if (StringUtils.isNotBlank(values[5])) {
            productRaiseInfo.setRaiseAmountRmb(new BigDecimal(values[5]));
        }
        if(StringUtils.isNotBlank(values[6])){
            productRaiseInfo.setRaiseShares(new BigDecimal(values[6]));
        }
        this.productRaiseInfoList.add(productRaiseInfo);
    }

    @Data
    @ToString
    public class ProductRaiseInfo {

        private String bankFinancingProductCode;

        private String areaCode;

        private BankFinancingProductRaiseInfoConst.CustomerType customerType;

        private String currencyCode;

        private BigDecimal raiseAmount;

        private BigDecimal raiseAmountRmb;

        private BigDecimal raiseShares;
    }
}
